package com.fc.advbox.service.impl;

import com.fc.advbox.dao.MenuDao;
import com.fc.advbox.entity.MenuEntity;
import com.fc.advbox.service.IMenuService;
import com.fc.advbox.service.IUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class MenuServiceImpl implements IMenuService {

    @Autowired
    private MenuDao menuDao;

    @Autowired
    private IUserRoleService userRoleService;

    @Override
    public MenuEntity queryObject(Integer menuId) {
        return menuDao.queryObject(menuId);
    }

    @Override
    public List<MenuEntity> queryList(Map<String, Object> map) {
        return menuDao.queryList(map);
    }

    @Override
    public List<MenuEntity> queryByRoleIds(List<Long> roleIds) {
        return menuDao.queryByRoleIds(roleIds);
    }

    @Override
    public List<MenuEntity> queryByUserIds(Long userId) {
        List<Long> roleIds = userRoleService.queryRoleIdList(userId);
        if (roleIds != null && roleIds.size()>0){
            return menuDao.queryByRoleIds(roleIds);
        }else{
            return null;
        }
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return menuDao.queryTotal(map);
    }

    @Override
    public void save(MenuEntity menu) {
        menuDao.save(menu);
    }

    @Override
    public void update(MenuEntity menu) {
        menuDao.update(menu);
    }

    @Override
    public void deleteBatch(Integer[] menuIds) {
        menuDao.deleteBatch(menuIds);
    }
}
